/*    */ package com.qmsk.business.megSend;
/*    */ 
/*    */ import java.util.Date;
/*    */ import java.util.Properties;
/*    */ import java.util.concurrent.Callable;
/*    */ import javax.mail.Message;
/*    */ import javax.mail.Message.RecipientType;
/*    */ import javax.mail.Session;
/*    */ import javax.mail.Transport;
/*    */ import javax.mail.internet.InternetAddress;
/*    */ import javax.mail.internet.MimeMessage;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ 
/*    */ public class MailRunner
/*    */   implements Callable<Boolean>
/*    */ {
/* 18 */   private static final Logger log = LoggerFactory.getLogger(MailRunner.class);
/*    */   private final MailInfo mailInfo;
/*    */   private static Properties props;
/*    */ 
/*    */   public MailRunner(MailInfo mailInfo)
/*    */   {
/* 23 */     this.mailInfo = mailInfo;
/* 24 */     getPropsIntance();
/*    */   }
/*    */ 
/*    */   private synchronized void getPropsIntance() {
/* 28 */     if (props == null) {
/* 29 */       props = new Properties();
/* 30 */       props.put("mail.smtp.host", this.mailInfo.getMailServerHost());
/* 31 */       props.put("mail.smtp.port", this.mailInfo.getMailServerPort());
/* 32 */       props.put("mail.smtp.auth", (this.mailInfo.isValidate()) ? "true" : 
/* 33 */         "false");
/* 34 */       props.put("mail.transport.protocol", this.mailInfo.getProtocol());
/*    */     }
/*    */   }
/*    */ 
/*    */   public Boolean call() throws Exception
/*    */   {
/* 40 */     Transport trans = null;
/*    */     try {
/* 42 */       Session session = Session.getInstance(props);
/* 43 */       session.setDebug(false);
/*    */ 
/* 45 */       Message mess = new MimeMessage(session);
/* 46 */       mess.setFrom(new InternetAddress(this.mailInfo.getFromAddress()));
/*    */ 
/* 48 */       mess.setRecipient(Message.RecipientType.TO, 
/* 49 */         new InternetAddress(this.mailInfo.getToAddress()));
/*    */ 
/* 51 */       mess.setSentDate(new Date());
/*    */ 
/* 53 */       mess.setSubject(this.mailInfo.getSubject());
/*    */ 
/* 55 */       mess.setText(this.mailInfo.getContent());
/*    */ 
/* 57 */       mess.setHeader("X-Priority", this.mailInfo.getMail_XPriority());
/*    */ 
/* 59 */       trans = session.getTransport(this.mailInfo.getProtocol());
/*    */ 
/* 61 */       trans.connect(this.mailInfo.getMailServerHost(), this.mailInfo.getUsername(), 
/* 62 */         this.mailInfo.getPassword());
/*    */ 
/* 64 */       trans.sendMessage(mess, mess.getAllRecipients());
/* 65 */       return Boolean.valueOf(true);
/*    */     } catch (Exception e) {
/* 67 */       log.error("Exception:" + e.getMessage());
/*    */     } finally {
/* 69 */       if (trans != null) {
/* 70 */         trans.close();
/*    */       }
/*    */     }
/* 73 */     return Boolean.valueOf(false);
/*    */   }
/*    */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.megSend.MailRunner
 * JD-Core Version:    0.5.3
 */